class RecordData < ActiveRecord::Base
  self.table_name = "record_data"
  # mount_uploader :pic, ImageUploader
   filterrific(
      available_filters: [
      :with_name,
      :with_status,
      :with_idcard,
      :with_phone,
      :with_upload_time_begin,
      :with_upload_time_end,
      :with_hotel_address_id
                 ]
               )
  # default for will_paginate
  self.per_page = 5

  scope :with_name, lambda { |ref_name|
    return nil  if ref_name.blank?
    where('record_data.name like ?', '%' + ref_name.to_s + '%')
  }

  scope :with_status, lambda { |ref_status|
    return nil  if ref_status.blank?
    where('record_data.status like ?', '%' + ref_status .to_s + '%')
  }


   scope :with_idcard, lambda { |ref_idcard|
    return nil  if ref_idcard.blank?
    where('record_data.idcard like ?', '%' + ref_idcard.to_s + '%')
  }
  
  scope :with_phone, lambda { |ref_phone|
    return nil  if ref_phone.blank?
    where('record_data.phone like ?', '%' + ref_phone.to_s + '%')
  }
  scope :with_upload_time_begin, lambda { |upload_time_begin|
    return nil  if upload_time_begin.blank?
    where('record_data.upload_time >= ?', upload_time_begin)
  }

  scope :with_upload_time_end, lambda { |upload_time_end|
    return nil  if upload_time_end.blank?
    where('record_data.upload_time <= ?', upload_time_end)
  }
  
  scope :with_hotel_address_id, lambda { |hotel_address_id|
    return nil  if hotel_address_id.blank?
    where('record_data.hotel_address_id like ?', '%' + hotel_address_id.to_s + '%')
  }
end
